/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dljk.core;

import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author Ariman
 */
public class DeckOld {

    private ArrayList<GameCard> cards;

    public DeckOld() {
        cards = new ArrayList<GameCard>();
    }

    public void createSolitareDeck() {
        HashMap map = new HashMap();
        for (int i = 2; i < 14; i++) {
            map.put(i, i);
        }
        map.put(14, 1);
        fillDeck(map);
    }

    private void fillDeck(HashMap map) {
        clearDeck();
        for (Object rank : map.keySet()) {
            int r = new Integer(rank.toString());
            int p = new Integer(map.get(rank).toString());
            cards.add(new GameCard(r, p, CardSuites.CLUBS));
            cards.add(new GameCard(r, p, CardSuites.DIAMONDS));
            cards.add(new GameCard(r, p, CardSuites.HEARTS));
            cards.add(new GameCard(r, p, CardSuites.SPADES));
        }
        shuffle();
    }

    private void fillDeck(int firstNumber) {
        clearDeck();
        for (int num = firstNumber; num < 15; num++) {
            cards.add(new GameCard(num, CardSuites.CLUBS));
            cards.add(new GameCard(num, CardSuites.DIAMONDS));
            cards.add(new GameCard(num, CardSuites.HEARTS));
            cards.add(new GameCard(num, CardSuites.SPADES));
        }
    }

    public void shuffle() {
        ArrayList<GameCard> tempCards = (ArrayList<GameCard>) cards.clone();
        int num = cards.size();
        cards.clear();
        for (int i = 0; i < num; i++) {
            int j = (int) Math.round(Math.random() * (num - 1 - i));
            cards.add(tempCards.get(j));
            tempCards.remove(j);
        }
    }

    public GameCard getTop() {
        if (cards.isEmpty()) {
            return null;
        } else {
            GameCard card = cards.get(cards.size() - 1);
            cards.remove(cards.size() - 1);
            return card;
        }
    }

    public void clearDeck() {
        cards.clear();
    }

    @Override
    public String toString() {
        return "Deck{" + "cards=" + cards + '}';
    }
}
